package org.dubnation.auth.controller;

import org.dubnation.auth.context.LoginContext;
import org.dubnation.base.util.AjaxResult;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/logout")
public class LogoutController {

    @DeleteMapping
    public AjaxResult deleteToken(HttpServletRequest request) {
        try {
            String token = request.getHeader("token");
            LoginContext.messageMap.remove(token);
            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }
    }
}
